<template>
  <basic-container>
    <avue-crud :option="option" :table-loading="loading" :data="data" :permission="permissionList"
               :before-open="beforeOpen" v-model="form" ref="crud" @row-update="rowUpdate" @row-save="rowSave"
               @row-del="rowDel"
               @search-change="searchChange" @search-reset="searchReset" @selection-change="selectionChange"
               @current-change="currentChange" @size-change="sizeChange" :upload-error="loadError" @on-load="onLoad">
      <template slot="menuLeft">
        <el-button type="danger" size="small" icon="el-icon-delete" plain v-if="permission.school_delete"
                   @click="handleDelete">删 除
        </el-button>
        <el-button v-if="userInfo.authority.indexOf('administrator') != -1" size="small"
                   @click="handleRole"
                   plain>设置App菜单
        </el-button>

        <!-- <el-button v-if="userInfo.authority.indexOf('administrator') != -1" size="small"
                   @click="handlePlate"
                   plain>设置板块
        </el-button> -->

        <el-button size="small"
                   @click="handleQuestionnaire"
                   plain>设置量表
        </el-button>
        <!--        <el-button type="primary" size="small" @click="teacherConfig">配置责任老师-->
        <!--        </el-button>-->
        <el-dialog title="配置责任老师" :visible.sync="dialogVisible" width="45%" :before-close="handleClose">
          <div class="optList">
            <div class="optListp">
              <label>学&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;校:</label>
              <el-input v-model="schoolName" placeholder="请输入学校名称" size="small" :disabled="true"></el-input>
            </div>
            <div class="optListp">
              <label>责任老师:</label>
              <el-select v-model="teacherName" filterable placeholder="请选择责任老师" size="small"
                         @change="handleCheckedCitiesChange">
                <el-option v-for="item in teachers" :key="item.id_string" :label="item.name" :value="item.id_string"
                           :disabled="item.is_Check">
                </el-option>
              </el-select>
            </div>

          </div>
          <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">取 消</el-button>
            <el-button type="primary" @click="amend">确 定</el-button>
          </span>
        </el-dialog>

        <el-dialog title="设置App菜单"
                   :visible.sync="box"
                   width="345px">
          <el-tabs type="border-card">
            <el-tab-pane label="家长端菜单权限">
              <el-button size="small"
                         @click="selectAll('home')"
                         type="primary"
                         plain>全选
              </el-button>
              <el-button size="small"
                         @click="cancelSelectAll('home')"
                         plain>取消全选
              </el-button>
              <el-tree :data="menuGrantList"
                       :check-strictly="true"
                       show-checkbox
                       style="max-height: 500px;overflow-x: auto;margin-top: 10px"
                       node-key="id"
                       ref="homeTreeMenu"
                       :default-checked-keys="menuTreeObj"
                       :props="props">
              </el-tree>
            </el-tab-pane>
            <el-tab-pane label="教师端菜单权限">
              <el-button size="small"
                         @click="selectAll('teacher')"
                         type="primary"
                         plain>全选
              </el-button>
              <el-button size="small"
                         @click="cancelSelectAll('teacher')"
                         plain>取消全选
              </el-button>
              <el-tree :data="teacherMenuGrantList"
                       :check-strictly="true"
                       show-checkbox
                       style="max-height: 500px;overflow-x: auto;margin-top: 10px"
                       node-key="id"
                       ref="teacherTreeMenu"
                       :default-checked-keys="teacherMenuTreeObj"
                       :props="props">
              </el-tree>
            </el-tab-pane>
          </el-tabs>
          <span slot="footer"
                class="dialog-footer">
        <el-button @click="box = false">取 消</el-button>
        <el-button type="primary"
                   @click="submit">确 定</el-button>
      </span>
        </el-dialog>


        <el-dialog title="设置板块"
                   :visible.sync="plateBox"
                   width="345px">
          <el-tabs type="border-card">
            <el-tab-pane label="板块列表">
              <el-button size="small"
                         @click="selectAll('plate')"
                         type="primary"
                         plain>全选
              </el-button>
              <el-button size="small"
                         @click="cancelSelectAll('plate')"
                         plain>取消全选
              </el-button>
              <el-tree :data="menuPlateList"
                       :check-strictly="true"
                       show-checkbox
                       style="max-height: 500px;overflow-x: auto;margin-top: 10px"
                       node-key="id"
                       ref="plateTree"
                       :default-checked-keys="plateTreeObj"
                       :props="props">
              </el-tree>
            </el-tab-pane>
          </el-tabs>
          <span slot="footer"
                class="dialog-footer">
        <el-button @click="plateBox = false">取 消</el-button>
        <el-button type="primary"
                   @click="plateSubmit">确 定</el-button>
           </span>
        </el-dialog>

        <el-dialog title="设置量表"
                   :visible.sync="quesBox"
                   width="50%">
          <el-tabs type="border-card">
            <el-tab-pane label="量表列表">
              <el-button size="small"
                         @click="selectAll('ques')"
                         type="primary"
                         plain>全选
              </el-button>
              <el-button size="small"
                         @click="cancelSelectAll('ques')"
                         plain>取消全选
              </el-button>
              <el-tree :data="menuQuesList"
                       :check-strictly="true"
                       show-checkbox
                       style="max-height: 500px;overflow-x: auto;margin-top: 10px"
                       node-key="id"
                       ref="quesTree"
                       :default-checked-keys="quesTreeObj"
                       :props="props">
              </el-tree>
            </el-tab-pane>
          </el-tabs>
          <span slot="footer"
                class="dialog-footer">
        <el-button @click="quesBox = false">取 消</el-button>
        <el-button type="primary"
                   @click="quesSubmit">确 定</el-button>
           </span>
        </el-dialog>


        <UploadStyle
          ref="uploadStyle"
          v-if="screenShotDialogVisible"
          :visible="screenShotDialogVisible"
          :img-url="imgUrl"
          :proportion="proportion"
          @closeDialog="closeDialog"
          @getImgURL="getImgURL"
        />
      </template>
    </avue-crud>
  </basic-container>
</template>

<script>
import {
  getList,
  add,
  update,
  remove,
  teacherList,
  Schooldetail,
  SchoolAdd,
  grantTree,
  getRole,
  grant,
  getPlateDataList,
  getSchoolPlateDataList,
  addOrEditSchoolPlate,
  getQuestTempList,
  getSchoolQuestTempList,
  addOrEditSchoolQuestTemp
} from "@/api/service/school";
import {mapGetters} from "vuex";

export default {
  data() {
    return {
      screenShotDialogVisible: false,
      imgUrl: "",
      _done: null,
      proportion: [200, 200],// 宽高的像素数组
      _uploadLoading: null,
      form: {},
      box: false,
      plateBox: false,//板块弹窗
      quesBox: false,//问卷弹窗
      props: {
        label: "title",
        value: "key"
      },
      menuGrantList: [],//家长端 Data数据
      menuTreeObj: [],//家长端 默认选中数据
      menusIds: [],//家长端 Data数据ID（设置全选时使用）
      teacherMenuGrantList: [],//教师端 Data数据
      teacherMenuTreeObj: [],//教师端 默认选中数据
      teacherMenusIds: [],//教师端 Data数据ID（设置全选时使用）
      menuPlateList: [],//板块 Data数据
      plateTreeObj: [],//板块  默认选中数据
      plateTreeIds: [],//板块  Data数据ID（设置全选时使用）
      menuQuesList: [],//问卷 Data数据
      quesTreeObj: [],//问卷  默认选中数据
      quesTreeIds: [],//问卷  Data数据ID（设置全选时使用）
      // selectionList: [],
      query: {type: '0'},
      loading: true,
      dialogVisible: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      teacherName: "",
      teachers: [], //配置教师列表
      schoolName: "", //配置学校名称
      sDetail: {},//学校详情
      jsId: 0, //新选中的教师id
      selectionList: [],
      option: {
        height: 'auto',
        calcHeight: 210,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        viewBtn: true,
        selection: true,
        tree: true,
        column: [
          {
            label: "主键",
            prop: "id",
            rules: [{
              required: true,
              message: "请输入主键",
              trigger: "blur"
            }],
            hide: true,
            display: false
            // ,
            // addDisplay:false,
            // editDisplay:false,
            // viewDisplay:false,
          },
          {
            label: "学校编码",
            search: true,
            overHidden: true,
            prop: "xxNo",
            rules: [{
              required: true,
              message: "请输入学校编码",
              trigger: "blur"
            }],
            maxlength: 50,
            showWordLimit: true
          },

          {
            label: "上级学校",
            prop: "parentName",
            type: "tree",
            // search: true,

            rules: [{
              required: false,
              message: "请选择上级学校名称",
              trigger: "blur"
            }],
            // dicUrl: "/api/PcPublicService/GetSchoolTreeSelect",
            // props: {
            //   label: "title",
            //   value: "id"
            // },
          },
          {
            label: "学校名称",
            prop: "xxName",
            search: true,
            overHidden: true,
            span: 24,
            rules: [{
              required: true,
              message: "请输入学校名称",
              trigger: "blur"
            }],
            maxlength: 100,
            showWordLimit: true
          },
          {
            label: "学校描述",
            prop: "xxDesc",
            type: "textarea",
            span: 24,
            minRows: 6,
            rules: [{
              required: true,
              message: "请输入学校描述",
              trigger: "blur"
            }],
            hide: true,
            maxlength: 500,
            showWordLimit: true
          },
          {
            label: "学校官网",
            prop: "xxUrl",
            rules: [{
              required: true,
              message: "请输入学校官网",
              trigger: "blur"
            }],
            hide: true,
            maxlength: 100,
            showWordLimit: true,
            span: 24
          },
          {
            label: "学校LOGO",
            prop: "xxLogo",
            rules: [{
              required: true,
              message: "请选择学校LOGO",
              trigger: "blur"
            }],
            type: 'upload',
            loadText: '附件上传中，请稍等',
            limit: 1,
            fileSize: 520,
            accept: "image/*",
            listType: 'picture-img',
            span: 12,
            propsHttp: {
              url: 'link',
              name: 'name',
              res: 'data'
            },
            action: '/api/localfiles/uploadPcFile',
            tip: '只能上传jpg/png文件，且不超过500kb',
            uploadBefore: (file, done, loading, col) => {
              this.screenShotDialogVisible = true
              const fileReader = new FileReader()
              fileReader.onload = (res) => {
                this.imgUrl = res.target.result
              }
              fileReader.readAsDataURL(file)
              this._done = done
              this._uploadLoading = loading
              this.proportion = [100, 100]
            }
          },
          {
            label: "背景图",
            prop: "xxBackground",
            rules: [{
              required: true,
              message: "请选择背景图",
              trigger: "blur"
            }],
            type: 'upload',
            loadText: '附件上传中，请稍等',
            limit: 1,
            // fileSize: 520,
            accept: "image/*",
            listType: 'picture-img',
            span: 12,
            propsHttp: {
              url: 'link',
              name: 'name',
              res: 'data'
            },
            hide: true,
            action: '/api/localfiles/uploadPcFile',
            tip: '只能上传jpg/png文件',
            uploadBefore: (file, done, loading, col) => {
              this.screenShotDialogVisible = true
              const fileReader = new FileReader()
              fileReader.onload = (res) => {
                // 给图片裁切传递参数
                this.imgUrl = res.target.result
              }
              fileReader.readAsDataURL(file)
              // 备份
              this._done = done
              this._uploadLoading = loading
              this.proportion = [375, 559]
            }
          },
          {
            label: "banner图",
            prop: "xxBanner",
            rules: [{
              required: true,
              message: "请选择banner图",
              trigger: "blur"
            }],
            type: 'upload',
            loadText: '附件上传中，请稍等',
            limit: 1,
            // fileSize: 520,
            accept: "image/*",
            listType: 'picture-img',
            span: 12,
            propsHttp: {
              url: 'link',
              name: 'name',
              res: 'data'
            },
            hide: true,
            action: '/api/localfiles/uploadPcFile',
            tip: '只能上传jpg/png文件',
            uploadBefore: (file, done, loading, col) => {
              this.screenShotDialogVisible = true
              const fileReader = new FileReader()
              fileReader.onload = (res) => {
                this.imgUrl = res.target.result
              }
              fileReader.readAsDataURL(file)
              this._done = done
              this._uploadLoading = loading
              this.proportion = [343, 126]
            }
          },
          {
            label: "学校风采封面图",
            prop: "xxStylePlot",
            rules: [{
              required: true,
              message: "请选择封面图",
              trigger: "blur"
            }],
            type: 'upload',
            loadText: '附件上传中，请稍等',
            limit: 1,
            // fileSize: 520,
            accept: "image/*",
            listType: 'picture-img',
            span: 12,
            propsHttp: {
              url: 'link',
              name: 'name',
              res: 'data'
            },
            hide: true,
            action: '/api/localfiles/uploadPcFile',
            tip: '只能上传jpg/png文件',
            uploadBefore: (file, done, loading, col) => {
              this.screenShotDialogVisible = true
              const fileReader = new FileReader()
              fileReader.onload = (res) => {
                this.imgUrl = res.target.result
              }
              fileReader.readAsDataURL(file)
              this._done = done
              this._uploadLoading = loading
              this.proportion = [343, 193]
            }
          },
          {
            label: "学校风采",
            prop: "xxStyle",
            rules: [{
              required: true,
              message: "请选择学校风采",
              trigger: "blur"
            }],
            type: 'upload',
            accept: "video/mp4",
            loadText: '附件上传中，请稍等',
            limit: 1,
            // fileSize: 520,
            listType: 'picture-img',
            span: 24,
            propsHttp: {
              url: 'link',
              name: 'name',
              res: 'data'
            },
            // fileSize: 10240,
            hide: true,
            action: '/api/localfiles/uploadPcFile',
            tip: '只能上传video/mp4文件',
          },
          {
            label: "学校校长",
            prop: "xxXz",
            overHidden: true,
            rules: [{
              required: true,
              message: "请输入学校校长",
              trigger: "blur"
            }],
            maxlength: 50,
            showWordLimit: true
          },
          // {
          //   label: "学校类型",
          //   prop: "xxType",
          //   type: 'select',
          //   search: true,
          //   overHidden: true,
          //   rules: [{
          //     required: true,
          //     message: "请选择学校类型",
          //     trigger: "blur"
          //   }],
          //   dicUrl: "/api/PcPublicService/GetDictionaryList?code=XUEXIAOLEIXING",
          //   props: {
          //     label: "dictValue",
          //     value: "dictKey"
          //   },
          //   dataType: "number",
          // },
          {
            label: "学校纬度",
            prop: "latitude",
            overHidden: true,
            rules: [{
              required: true,
              message: "请输入学校纬度",
              trigger: "blur"
            }],
            maxlength: 50,
            showWordLimit: true,
            hide: true,
          },
          {
            label: "学校经度",
            prop: "longitude",
            overHidden: true,
            rules: [{
              required: true,
              message: "请输入学校经度",
              trigger: "blur"
            }],
            maxlength: 50,
            hide: true,
            showWordLimit: true
          },
          {
            label: "学校地址",
            prop: "xxAddr",
            type: "textarea",
            span: 24,
            minRows: 6,
            rules: [{
              required: true,
              message: "请输入学校地址",
              trigger: "blur"
            }],
            hide: true,
            maxlength: 100,
            showWordLimit: true
          },
          {
            label: "所在省",
            prop: "xxProvinceCode",
            search: true,
            overHidden: true,
            rules: [{
              required: true,
              message: "请选择所在省",
              trigger: "blur"
            }],
            type: 'select',
            props: {
              label: 'name',
              value: 'code'
            },
            cascader: ['xxCityCode'],
            cascaderIndex: 1,
            dicUrl: '/api/ManageSchool/GetRegionSelectList?code=00',
          },
          {
            label: "所在市",
            prop: "xxCityCode",
            search: true,

            rules: [{
              required: true,
              message: "请选择所在市",
              trigger: "blur"
            }],
            type: 'select',
            cell: true,

            props: {
              label: 'name',
              value: 'code'
            },
            dicUrl: '/api/ManageSchool/GetRegionSelectList?code={{key}}',
            cascader: ['xxAreaCode'],
            cascaderIndex: 1,
            hide: true
          },

          {
            label: "所在县",
            prop: "xxAreaCode",
            search: true,

            rules: [{
              required: true,
              message: "请选择所在县",
              trigger: "blur"
            }],
            type: 'select',
            props: {
              label: 'name',
              value: 'code'
            },
            dicUrl: '/api/ManageSchool/GetRegionSelectList?code={{key}}',
            hide: true
          },
          {
            label: "学校性质",
            type: 'select',
            prop: "xxNature",
            search: true,
            overHidden: true,
            rules: [{
              required: true,
              message: "请选择学校性质",
              trigger: "blur"
            }],
            dicUrl: "/api/PcPublicService/GetDictionaryList?code=XUEXIAOXINGZHI",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
          },
          {
            label: "管理机构",
            prop: "xxManagemenOrg",
            search: true,
            overHidden: true,
            rules: [{
              required: true,
              message: "请输入学校管理机构",
              trigger: "blur"
            }],
            maxlength: 100,
            showWordLimit: true
          },
          {
            label: "机构编码",
            prop: "xxManagementOrgCode",
            rules: [{
              required: true,
              message: "请输入机构编码",
              trigger: "blur"
            }],
            hide: true,
            maxlength: 50,
            showWordLimit: true
          },
          {
            label: "机构层级",
            type: 'select',
            prop: "xxManagementLevel",
            rules: [{
              required: true,
              message: "请选择机构层级",
              trigger: "blur"
            }],
            hide: true,
            dicUrl: "/api/PcPublicService/GetDictionaryList?code=GUANLICENGJI",
            props: {
              label: "dictValue",
              value: "dictKey"
            },
            dataType: "number",
          },


        ]
      },
      data: []
    };
  },
  mounted() {
    this.$refs.crud.dicInit('cascader');
  },
  computed: {
    ...mapGetters(["permission", "JSuserInfo","userInfo"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission.school_add, false),
        viewBtn: this.vaildData(this.permission.school_view, false),
        delBtn: this.vaildData(this.permission.school_delete, false),
        editBtn: this.vaildData(this.permission.school_edit, false)
      };
    },
    js_Id() {
      return this.JSuserInfo.js_Id
    },
    ids() {
      let ids = [];
      this.selectionList.forEach(ele => {
        ids.push(ele.id);
      });
      return ids.join(",");
    }
  },
  methods: {
    selectAll(type) {
      if (type === 'home') {
        this.$refs.homeTreeMenu.setCheckedKeys(this.menusIds)
      } else if (type === 'teacher') {
        this.$refs.teacherTreeMenu.setCheckedKeys(this.teacherMenusIds)
      } else if (type === 'plate') {
        this.$refs.plateTree.setCheckedKeys(this.plateTreeIds)
      } else if (type === 'ques') {
        this.$refs.quesTree.setCheckedKeys(this.quesTreeIds)
      }
    },
    cancelSelectAll(type) {
      if (type === 'home') {
        this.$refs.homeTreeMenu.setCheckedKeys([])
      } else if (type === 'teacher') {
        this.$refs.teacherTreeMenu.setCheckedKeys([])
      } else if (type === 'plate') {
        this.$refs.plateTree.setCheckedKeys([])
      } else if (type === 'ques') {
        this.$refs.quesTree.setCheckedKeys([])
      }
    },
    loadError(error) {
      this.$message({
        type: "error",
        message: error
      });
    },
    rowSave(row, done, loading) {
      row.id = row.id === '' ? '0' : row.id
      row.parentId = row.parentId === '' ? '0' : row.parentId
      add(row).then(() => {
        done();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        window.console.log(error);
        loading();
      });
    },
    rowUpdate(row, index, done, loading) {
      console.log('111111', row)
      row.parentId = row.parentId === '' ? '0' : row.parentId

      update(row).then(() => {
        done();
        this.onLoad(this.page);
        this.$message({
          type: "success",
          message: "操作成功!"
        });
      }, error => {
        window.console.log(error);
        loading();
      });
    },
    rowDel(row) {
      this.$confirm("确定将选择的父级、子级学校和数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove({ids: row.id});
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
        });
    },
    handleDelete() {
      if (this.selectionList.length === 0) {
        this.$message.warning("请选择至少一条数据");
        return;
      }
      this.$confirm("确定将选择数据删除?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          return remove({ids: this.ids});
        })
        .then(() => {
          this.onLoad(this.page);
          this.$message({
            type: "success",
            message: "操作成功!"
          });
          this.$refs.crud.toggleSelection();
        });
    },
    //配置教师
    teacherConfig() {
      let list = this.selectionList
      if (list.length == 1) {
        this.dialogVisible = true
        this.teacher(list[0].id, list[0].xxName)
      } else if (list.length == 0) {
        this.$message.error('请先选择学校')
      } else if (list.length > 1) {
        this.$message.error('只能选择一所学校')
      }
    },
    handleCheckedCitiesChange(e) {
      this.jsId = e
    },
    //教师列表
    teacher(id, name) {
      teacherList(id).then(res => {
        this.teachers = res.data.data
        this.schoolName = name
      })
      Schooldetail(id).then(res => {
        this.teacherName = res.data.data.js_name
        this.sDetail = res.data.data
      })
    },
    amend() {
      let id = this.sDetail.id + ''
      let School_id = this.sDetail.school_id + ''
      let AppUserId = this.js_Id + ''
      let Js_id = this.jsId + ''
      let data = {
        id,
        School_id,
        AppUserId,
        Js_id,
      }
      SchoolAdd(data).then(res => {
        this.dialogVisible = false
        if (res.data.code == 0) {
          this.$message({
            message: '修改成功',
            type: 'success'
          });
        } else {
          this.$message({
            message: '修改失败',
            type: 'error'
          });
        }
      })
      this.teacherName = ""
    },
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    searchReset() {
      this.query = {};
      this.onLoad(this.page);
    },
    searchChange(params, done) {
      params.type = 1
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      this.query.type = 0;
      done();
    },
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    onLoad(page, params = {}) {
      this.loading = true;
      console.log(params)
      getList(page.currentPage, page.pageSize, Object.assign(params, this.query)).then(res => {
        // const data = res.data.data;
        // this.page.total = data.total;
        this.data = res.data.data;
        this.loading = false;
        this.selectionClear();
      });
    },
    handleRole() {
      if (this.selectionList.length !== 1) {
        this.$message.warning("只能选择一条数据");
        return;
      }
      this.menuTreeObj = [];
      this.teacherMenuTreeObj = []
      grantTree()
        .then(res => {
          this.menuGrantList = res.data.data.jzMenus;
          this.menusIds = res.data.data.jzMenusIds;
          this.teacherMenuGrantList = res.data.data.jsMenus;
          this.teacherMenusIds = res.data.data.jsMenusIds;
          getRole({schoolId: this.ids}).then(res => {
            // 菜单权限
            this.menuTreeObj = res.data.data.jzMenuIds;
            this.teacherMenuTreeObj = res.data.data.jsMenuIds;
            this.box = true;
          });
        });
    },
    // 权限设置提交
    submit() {
      const homeMenuList = this.$refs.homeTreeMenu.getCheckedKeys();
      const teacherMenuList = this.$refs.teacherTreeMenu.getCheckedKeys();
      let params = {
        schoolId: this.ids,
        jzMenuIds: homeMenuList,
        jsMenuIds: teacherMenuList
      }
      grant(params).then(() => {
        this.box = false;
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        this.onLoad(this.page);
      });
    },
    //设置板块列表
    handlePlate() {
      if (this.selectionList.length !== 1) {
        this.$message.warning("只能选择一条数据");
        return;
      }
      this.menuPlateList = []
      this.plateTreeIds = []
      this.plateTreeObj = []
      getPlateDataList()
        .then(res => {
          this.menuPlateList = res.data.data.plateData;
          this.plateTreeIds = res.data.data.plateDataIds;
          getSchoolPlateDataList({schoolId: this.ids}).then(res => {
            // 菜单权限
            this.plateTreeObj = res.data.data;
            this.plateBox = true;
          });
        });
    },
    //设置问卷列表
    handleQuestionnaire() {
      if (this.selectionList.length !== 1) {
        this.$message.warning("只能选择一条数据");
        return;
      }
      this.menuQuesList = [] //问卷 Data数据
      this.quesTreeObj = [] //问卷 默认选中数据
      this.quesTreeIds = [] //问卷 Data数据ID（设置全选时使用）
      getQuestTempList({schoolId: this.selectionList[0].id})
        .then(res => {
          this.menuQuesList = res.data.data.questTempDtos;
          this.quesTreeIds = res.data.data.questTempIds;
          getSchoolQuestTempList({schoolId: this.ids}).then(res => {
            // 菜单权限
            this.quesTreeObj = res.data.data;
            this.quesBox = true;
          });
        });
    },
    //板块提交
    plateSubmit() {
      const plateMenuList = this.$refs.plateTree.getCheckedKeys();
      let params = {
        schoolId: this.ids,
        plateId: plateMenuList,
      }
      addOrEditSchoolPlate(params).then(() => {
        this.plateBox = false;
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        this.onLoad(this.page);
      });
    },
    //问卷提交
    quesSubmit(){
      const quesMenuList = this.$refs.quesTree.getCheckedKeys();
      let params = {
        schoolId: this.ids,
        plateId: quesMenuList,
      }
      addOrEditSchoolQuestTemp(params).then(() => {
        this.quesBox = false;
        this.$message({
          type: "success",
          message: "操作成功!"
        });
        this.onLoad(this.page);
      });
    },
    closeDialog(val) {
      if (this._uploadLoading !== null) {
        this._uploadLoading();
        this._uploadLoading = null
      }
      this.screenShotDialogVisible = val;
    },
    getImgURL(data) {
      if (this._done !== null) {
        this._done(data);
        this._done = null
      }
      this.closeDialog(false)
    }
  }
};
</script>

<style scoped>
.optList {
  display: flex;
  justify-content: space-between;
  width: 90%;
}

.optListp {
  width: 280px;
  display: flex;
}

.optListp label {
  width: 100px;
  line-height: 30px;
}
</style>
